package br.com.mtg.movethegarbage.impl;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.util.Log;
import br.com.mtg.movethegarbage.framework.Audio;
import br.com.mtg.movethegarbage.framework.Music;
import br.com.mtg.movethegarbage.framework.Sound;

public class GameAudio extends Audio
{

	public GameAudio(Activity activity)
	{
		super(activity);
		activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
	}

	@Override
	public Sound newSound(String fileName)
	{
		try
		{
			AssetFileDescriptor assetFileDescriptor = assetManager.openFd(fileName);
			int soundID = pool.load(assetFileDescriptor, 0);
			return new Sound(pool, soundID);
		}
		catch (Exception e)
		{
			Log.e("Audio:", "Could not create sound");
		}
		return null;
	}

	@Override
	public Music newMusic(String fileName)
	{
		try
		{
			AssetFileDescriptor assetFileDescriptor = assetManager.openFd(fileName);
			return new Music(assetFileDescriptor);
		}
		catch (Exception e)
		{
			Log.e("Audio:", "Could not create music");
		}
		return null;
	}

	@Override
	public void playSound(Sound sound, float volume)
	{
		if (soundEnabled)
			sound.play(volume);
	}

	@Override
	public void playMusic(Music music)
	{
		if (soundEnabled)
			music.play();
	}
}
